package com.keke.beauty.utils.tools;

import com.github.pagehelper.PageInfo;
import com.keke.beauty.utils.enums.ResultEnum;
import com.keke.beauty.utils.pojo.Result;
import com.keke.beauty.utils.pojo.TableInfo;

/**
 * @Description 返回参数工具
 * @Date 2017年7月15日 下午11:31:23
 * @author wei9dao
 */
public class ResultUtil {

    public static <T> Result successTable(PageInfo<T> list) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg("success");
        
        TableInfo<T> tablePage = new TableInfo<T>();
        tablePage.setTotal(list.getTotal());
        tablePage.setPageNum(Math.max(list.getPageNum(), 1));
        tablePage.setPageSize(list.getPageSize());
        tablePage.setList(list.getList());
        
        result.setData(tablePage);
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    public static Result success(){
        return success(null);
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public static Result error(Integer code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}
